<?php

namespace app\app\controller;

use app\BaseController;
use app\app\model\FileModel;

class File extends BaseController
{
    public function info()
    {

        $query = $this->request->param();
        $id = $query['id'];
        $res = FileModel::where(['file_id' => $id])->find();
        $this->success('success', $res);
    }

    public function forceDownload()
    {
        $query = $this->request->param();
        $id = $query['id'];
        $res = FileModel::where(['file_id' => $id])->find();
        if (empty($res)) {
            return '文件为空';
        }
        header('Content-Type: application-x/force-download');
        header('Content-Disposition: attachment; filename="' . basename($res['file_name']) . '"');
        header('Pragma: no-cache');
        return readfile($res['file_path']);
    }
}
